package club.banyuan.reserve.service;

import club.banyuan.reserve.dto.PositionParam;
import club.banyuan.reserve.mapper.PositionMapper;
import club.banyuan.reserve.model.Position;
import club.banyuan.reserve.model.PositionExample;
import club.banyuan.reserve.vo.PositionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author HanChao
 * 描述信息：
 */
@Service
public class AdminSeatServiceImpl implements AdminSeatService{

    @Autowired
    private PositionMapper positionMapper;

    @Override
    public List<PositionVo> showPositionList() {

        List<Position> positionList = positionMapper.selectByExample(new PositionExample());

        List<PositionVo> list = new ArrayList<>();
        for (Position p: positionList) {

            PositionVo position = new PositionVo();
            position.setId(p.getId());
            position.setName(p.getName());
            position.setStatus(p.getStatus());

            list.add(position);
        }

        return list;
    }

    @Override
    public void editPositionByParam(PositionParam param) {

        Position position = new Position();
        position.setId(param.getId());
        position.setName(param.getName());
        position.setStatus(param.getStatus());

        PositionExample positionExample = new PositionExample();
        positionExample.createCriteria()
                .andNameEqualTo(param.getName())
                .andIdEqualTo(param.getId());
        positionMapper.updateByExampleSelective(position, positionExample);
    }
}
